#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iostream>

#include "TROOT.h" 
#include "TF1.h"
#include "TH1F.h"
#include "TApplication.h"
#include "TFile.h"
#include "TNetFile.h"
#include "TRandom.h"
#include "TTree.h"
#include "TBranch.h"
#include "TClonesArray.h"
#include "TStopwatch.h"
#include "TCanvas.h"
#include "TRandom3.h"
#include "TGraph.h"
#include "TMath.h"
#include "TArc.h"
#include "TVirtualFitter.h"

#include "TTrackerHit.h"
#include "TEvent.h"

int main (int argc, char const* argv[])
{
	TFile *f = new TFile("test.root","recreate");
	TTree *t = new TTree("t","test");
	double x;
	TEvent *evt = new TEvent();
	t->Branch("x",&x,"x/D");
	t->Branch("evt",evt);

	//TTrackerHit *aHit =new TTrackerHit();
	TTrackerHit aHit;
	aHit.SetHitType((TTrackerHit::HitType)0);

	for (int i = 0; i < 10; i++) {
		evt->SetEvtId(i);
		aHit.SetDetID(i);
		x = i;
		//evt->SetNoOfHits(1);
		evt->AddHit(aHit);
		t->Fill();
	}
	
	t->Write();
	//t->Print();
	f->Close();

	TEvent *evt2 = new TEvent();
	f = TFile::Open("test.root","r");
	t = (TTree*)f->Get("t");
	t->SetBranchAddress("evt",&evt2);
	int nevt = t->GetEntries();
	printf("nevt: %d\n",nevt);
	for (int i = 0; i < nevt; i++) {
		t->GetEntry(i);
		printf("NoOfHits: %d\n",evt2->GetNoOfHits());
		printf("Det: %d\n",evt2->GetHit(0).GetDetID());
	}

	return 0;
}
